package com.jd.basic.service.impl;

import com.jd.basic.mapper.BaseMapper;
import com.jd.basic.query.BaseQuery;
import com.jd.basic.service.BaseService;
import com.jd.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 小林同学
 * @version 1.0
 * @description: TODO
 * @date 2023/2/24 12:28
 */
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public void delete(Long id) {
        System.out.println(id);
        baseMapper.delete(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        baseMapper.batchDelete(ids);
    }
    @Override
    public PageList queryByPage(BaseQuery baseQuery) {
        Integer totals = baseMapper.queryByCount(baseQuery);
        if (totals == 0) {
            return new PageList<T>(0,new ArrayList<>());
        }
        List<T> data = baseMapper.queryByPage(baseQuery);
        System.out.println(data);
        return new PageList<T>(totals, data);
    }
}
